home *** CD-ROM | disk | FTP | other *** search
- void computeLightViewVectors(
- in float4 inPositionObj,
- in float3 inNormalObj,
- in float3 inTangentObj,
- in float4 inCameraPosObj,
- #ifdef IS_DIRECTIONAL_LIGHT
- in float3 lightDirObj,
- #else
- in float4 inLightPosObj,
- #endif
- out float3 outLightDirTang,
- out float3 outEyeVectorTang)
- {
- float3 normal = normalize(inNormalObj);
-
- #ifdef INVERT_TANGENT_SPACE
- // If necessary, invert the normal. This is mostly
- // useful when drawing back faces for transparency.
- //
- normal = normal * -1.0;
- #endif
-
- float3 tangent = inTangentObj - normal * dot(inTangentObj, normal);
- tangent = normalize(tangent);
-
- float3 binormal = cross(normal, tangent);
- binormal = normalize(binormal);
-
- // Compute the tangent space vectors
- //
-
- #ifdef IS_DIRECTIONAL_LIGHT
- #else
- float3 lightDirObj = (inLightPosObj - inPositionObj).xyz;
- #endif
- outLightDirTang = float3(dot(lightDirObj, tangent),
- dot(lightDirObj, binormal),
- dot(lightDirObj, normal));
-
- // Compute the eye vector in object space (vector from eye to vertex position)
- float3 eyeVectorObj = (inCameraPosObj - inPositionObj).xyz;
- outEyeVectorTang = float3(dot(eyeVectorObj, tangent),
- dot(eyeVectorObj, binormal),
- dot(eyeVectorObj, normal));
- }
-
- void computeLightVector(
- in float4 inPositionObj,
- in float3 inNormalObj,
- in float3 inTangentObj,
- #ifdef IS_DIRECTIONAL_LIGHT
- in float3 lightDirObj,
- #else
- in float4 inLightPosObj,
- #endif
- out float3 outLightDirTang)
- {
- float3 normal = normalize(inNormalObj);
-
- #ifdef INVERT_TANGENT_SPACE
- // If necessary, invert the normal. This is mostly
- // useful when drawing back faces for transparency.
- //
- normal = normal * -1.0;
- #endif
-
- float3 tangent = inTangentObj - normal * dot(inTangentObj, normal);
- tangent = normalize(tangent);
-
- float3 binormal = cross(normal, tangent);
- binormal = normalize(binormal);
-
- // Compute the tangent space vectors
- //
-
- #ifdef IS_DIRECTIONAL_LIGHT
- #else
- float3 lightDirObj = (inLightPosObj - inPositionObj).xyz;
- #endif
- outLightDirTang = float3(dot(lightDirObj, tangent),
- dot(lightDirObj, binormal),
- dot(lightDirObj, normal));
- }
-
- void computeTangentToObjMatrix(
- in float3 inNormalObj,
- in float3 inTangentObj,
- out float3x3 outTangentToObjMatrix)
- {
- // Compute an orthonormal tangent basis.
- //
-
- float3 normal = normalize(inNormalObj);
-
- float3 tangent = inTangentObj - normal * dot(inTangentObj, normal);
- tangent = normalize(tangent);
-
- float3 binormal = cross(normal, tangent);
- binormal = normalize(binormal);
-
- outTangentToObjMatrix[0] = tangent;
- outTangentToObjMatrix[1] = binormal;
- outTangentToObjMatrix[2] = normal;
- }
-